package com.intellagric.controller.module.ift_manufactor;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.IftManufactor;
import com.intellagric.service.iftmonitor.ift_manufactor.ManufactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/20
 * @DESC： 厂商信息管理
 */
@Controller
public class ManufatorController {

    @Autowired
    private ManufactorService manufactorService;

    /**
     * 添加厂商信息
     * @Param manufactor
     * @return ResponseMessage
     */
    @RequestMapping("/manufator/add")
    @ResponseBody
    public ResponseMessage add(IftManufactor manufactor) {
        //初始化信息
        manufactor.setId(UUID.randomUUID().toString().replaceAll("-",""));
        manufactor.setCreateDate(new Date());
        manufactor.setUpdateDate(new Date());
        return manufactorService.addManufator(manufactor);
    }

    /**
     * 删除厂商信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/manufator/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return manufactorService.deleteManufator(id);
    }

    /**
     * 修改厂商信息
     * @Param manufactor
     * @return ResponseMessage
     */
    @RequestMapping("/manufator/edit")
    @ResponseBody
    public ResponseMessage edit(IftManufactor manufactor) {
        manufactor.setCreateDate(null);
        manufactor.setUpdateDate(new Date());
        return manufactorService.editManufator(manufactor);
    }

    /**
     * 查询厂商信息
     * @return IftManufator
     */
    @RequestMapping("/manufator/{id}")
    @ResponseBody
    public IftManufactor get(@PathVariable String id) {
        return manufactorService.getManufatorById(id);
    }

    /**
     * 查询厂商信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/manufator/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return manufactorService.getManufatorList();
    }

    /**
     * 分页查询厂商信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/manufator/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return manufactorService.getManufatorPage(page,limit);
    }


}
